package com.mate.cloud.sensitive.processor;

import cn.hutool.crypto.SecureUtil;
import cn.hutool.crypto.symmetric.AES;
import lombok.Data;

/**
 * AES的默认模式是：AES/ECB/PKCS5Padding
 * @author:         MI
 * @email:          448341911@qq.com
 * @createTime:     2025/2/11 17:37
 * @updateUser:     MI
 * @updateTime:     2025/2/11 17:37
 * @updateRemark:   修改内容
 * @version:        v1.0
 */
@Data
public class AESProcessor implements SecurityProcessor {

    private String secret;

    private AES aes;

    public AESProcessor(String secret) {
        this.secret = secret;
        this.aes = SecureUtil.aes(SecureUtil.decode(secret));
    }

    @Override
    public byte[] decrypt(String text) {
        return aes.decrypt(text);
    }

    @Override
    public byte[] encrypt(byte[] data) {
        return aes.encrypt(data);
    }
}
